﻿using System;
using System.Windows.Forms;
using App.SolInf.Modelo;
using NHibernate;
using NHibernate.Criterion;

namespace App.SolInf.Vista.Controls
{
    public partial class FiltroBusquedaPresupuesto : UserControl, IFiltroBusqueda
    {
        public FiltroBusquedaPresupuesto()
        {
            InitializeComponent();
        }

        public ICriteria AplicarFiltro(ICriteria query)
        {
            var id = txtId.Text.Trim();
            if( !String.IsNullOrEmpty(id))
                query.Add(new LikeExpression("Id", id));

            var cliente = txtCliente.Text.Trim();
            if (!String.IsNullOrEmpty(cliente))
                query.Add(new LikeExpression("Cliente.RazonSocial", cliente, MatchMode.Anywhere));

            if (dateFrom.Checked)
            {
                var now = dateFrom.Value;
                query.Add(new SimpleExpression("FechaAlta", new DateTime(now.Year, now.Month, now.Day, 0, 0, 0, 0), ">="));
            }
            
            if (dateTo.Checked)
            {
                var now = dateFrom.Value;
                query.Add(new SimpleExpression("FechaAlta",new DateTime(now.Year, now.Month, now.Day,23,59,59,999), "<="));
            }
            
            return query;
        }


    }
}
